//q5b.cpp
//The program takes a, b and c. Returns the values of x for ax^2 + bx + c = 0
//
//Binyamin 22 december 2017
//-----------------------------------------------------------
#include <iostream>
#include <math.h>

using namespace std;

// 1. Prompt the user for a, b and c.
// 2. Capture a, b and c.
// 3. calculate the value of x.
// 4. print x.

int main()
{
	double a; // a - a as inserted by the user
	double b; // b - b as inserted by the user
	double c; // c - c as inserted by the user
	double x1, x2; // x* - the value of x for ax^2+bx+c=0
	double delta; // delta - the delta value for the equation.

	//prompts
	cout << "Please enter a, b and c for ax^2+bx+c=0" << endl;
	cin >> a >> b >> c;

	//logic
	if( a == 0)
	{
		x1 = c/b * -1;
		cout << "The equation have one solution: " << x1 << endl;
	}
	else // a!=0
	{
		delta = b*b - 4 * a * c;
		if(delta == 0)
		{
			x1 = -1*b/2*a;
			cout << "The equation have one solution: " << x1 << endl;
		}
		else if(delta > 0)
		{
			x1 = (-1*b + sqrt(delta))/2*a;
			x2 = (-1*b - sqrt(delta))/2*a;
			cout << "The equation have two solutions:" << endl \
				<< "x1 = " << x1 << endl \
				<< "x2 = " << x2 << endl;
		}
		else // delta < 0
		{
			cout << "The equation have no solutions" << endl;
		}

	}
	return 0;
}
//output
//Please enter a, b and c for ax^2+bx+c=0
//1 6 -7
//The equation have two solutions:
//x1 = 1
//x2 = -7
